#include<iostream>
#include<algorithm>
#include<list>
using namespace std;
const double EPS = 1e-6;

struct Term
{
	double val;
	int order;
};
inline void input_poly(list<Term> &p)
{
	int N; cin>>N;
	for(int i = 0;i<N;++i)
	{
		Term tmp; cin>>tmp.order>>tmp.val;
		p.push_back(tmp);
	}
}
inline bool isequal_double(double a, double b)
{
	double abs_ab = a-b > 0 ? a-b : b-a;
	if(abs_ab<EPS) return true;
	return false;
}

// op and delta are sort in desed order, do op = op+delta
list<Term>& operator+=(list<Term>& op,list<Term>& delta)
{
	list<Term>::iterator pop = op.begin(),pdelta = delta.begin();
	while(pop!=op.end() && pdelta!=delta.end())
	{
		if(pop->order > pdelta->order) pop++;
		else if(pop->order < pdelta->order)
			{ op.insert(pop,*pdelta); pdelta++; }
		else
		{
			if(isequal_double(pop->val,-pdelta->val)) 
				pop = op.erase(pop); 
			else { pop->val+=pdelta->val; pop++; }
			pdelta++;
		}
	}
	if(pop==op.end())
		while(pdelta!=delta.end()) op.push_back(*pdelta++); 
	return op;
}

int main(int argc, char const *argv[])
{
	freopen("test.txt","r",stdin);
	list<Term> p1,p2;
	input_poly(p1); input_poly(p2);

	// mul: do add for n times
	list<Term> res;
	for(auto t:p2)
	{
		list<Term> tmp;
		for(auto x:p1)
		{
			Term tmpt{x.val*t.val,x.order+t.order};
			tmp.push_back(tmpt);
		}
		res+=tmp;
	}

	cout<<res.size();
	for(auto &t:res)
		printf(" %d %.1f",t.order,t.val);
	
	return 0;
}
